<div id="app">
    <section class="content-header">
        <h1>
            <small>商品租期展示</small>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">
                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                                <a style="margin:0px 5px;" href="/admin/goods/goodsEdit?goods_id={{$goods['goods_id']}}" class="btn btn-sm btn-default" title="商品编辑"> <span class="hidden-xs">商品编辑</span></a>
                                <a style="margin:0px 5px;" href="/admin/goods/goodsAttr?goods_id={{$goods['goods_id']}}" class="btn btn-sm btn-default" title="规格"> <span class="hidden-xs">规格</span></a>

                                <a style="margin:0px 5px;" href="/admin/goods/sku?goods_id={{$goods['goods_id']}}" class="btn btn-sm btn-default" title="属性"> <span class="hidden-xs">属性</span></a>
                                <a style="margin:0px 5px;" href="/admin/goods/goodsAddImg?goods_id={{$goods['goods_id']}}" class="btn btn-sm btn-default" title="图片"> <span class="hidden-xs">图片</span></a>
                                <a href="/admin/goods/goodsLeaseSet?goods_id={{$goods['goods_id']}}" class="btn btn-sm btn-default" title="设置租期"> <span class="hidden-xs">添加租期</span></a>

                            </div>
                        </div>

                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                            </div>
                        </div>

                        <span>
   {{--<input type="checkbox" class="grid-select-all" />&nbsp;--}}
    <div class="btn-group">

    </div>

    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>
<a class="btn btn-sm btn-primary" onclick="javascript:history.go(-1);" title="返回"> <span class="hidden-xs"> 返回</span></a>

  </span>
                    </div>




                    <!-- /.box-header -->
                    <!--数据列表开始   -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead >
                            <tr >
                                <th>租期id </th>
                                <th>商品id </th>
                                <th>商品名称</th>
                                <th>商品sku</th>
                                <th>租期数</th>
                                <th>总租金</th>
                                <th>押金</th>
                                <th>买断金</th>


                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>

                            @if (!empty($list))
                                @foreach($list as $v)
                                        <tr>
                                            <td >
                                                {{ $v['id'] }}
                                            </td>
                                            <td >
                                                {{ $v['goods_id'] }}
                                            </td>
                                            <td >
                                                 {{$goods['goods_name']}}
                                            </td>
                                            <td >
                                                {{$v['sku_str']}}
                                            </td>
                                            <td >
                                                {{$v['term_num']}}
                                            </td>
                                            <td >
                                                {{$v['rent_price']}}
                                            </td>
                                            <td >
                                                {{$v['deposit_price']}}
                                            </td>
                                            <td >
                                                {{$v['buyout_price']}}
                                            </td>



                                            {{--<td >--}}
                                                {{--@if($v['is_hidden']==1)--}}
                                                    {{--<button onclick="del(this,{{$v['cate_id']}})" style="color:blue;">否</button>--}}
                                                {{--@else--}}
                                                    {{--<button onclick="del(this,{{$v['cate_id']}})" style="color:red;">是</button>--}}
                                                {{--@endif--}}
                                            {{--</td>--}}


                                            <td >
                                                <a href="/admin/goods/goodsLeaseEdit?id={{$v['id']}}">
                                                    编辑
                                                </a>
                                            </td>
                                        </tr>
                                        @if($v['term'])
                                            @foreach($v['term'] as $kk=> $vv)
                                                <tr>
                                                    <td colspan="3">第{{$kk+1}}期</td>
                                                    <td colspan="3">本期天数：{{$vv['day_num']}}</td>
                                                    <td colspan="3">本期租金：{{$vv['price']}}</td>
                                                </tr>

                                            @endforeach
                                        @endif
                                        @endforeach
                                    @endif
                            </tbody>
                        </table>
                    </div>
                    <!--数据列表结束-->



                    <!-- /.box-body -->
                </div>
            </div>
        </div>

    </section>
</div>

<script data-exec-on-popstate>
    $(function () {
        //tr选中样式控制
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });

        //单条数据删除
        $('.grid-row-delete').unbind('click').click(function() {
            var id = $(this).data('id');
            console.log(id);
            swal({
                title: "确认删除?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        $.ajax({
                            method: 'POST',
                            url: '/admin/goods/delete',
                            data: {
                                _method:'delete',
                                _token:LA.token,
                                goods_id:id
                            },
                            dataType:'json',
                            success: function (data) {
                                if(data.status==1){
                                    swal(data.message, '', 'success');
                                    $.pjax.reload('#pjax-container');
                                }else{
                                    swal(data.message, '', 'error');
                                }
                                resolve(data);
                            }
                        });
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        swal(data.message, '', 'success');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });

    });

    //删除或不删除
    function del(e,id){
        $.ajax({
            url:"/admin/category/ajaxDel",
            data:{goods_id:id,_token:LA.token},
            type:'post',
            dataType:'json',
            success:function(m){
                if(m.status==1){
                    if(m.data.is_delete==1){
                        $(e).html('是').css("color",'red');
                    }else{
                        $(e).html('否').css("color",'blue');
                    }
                    toastr.success('ok');
                }else{
                    swal(m.message, '', 'error');
                }
            }
        });
    }
</script>